package com.qf.service.impl;

import com.qf.dao.CartDao;
import com.qf.dao.impl.CartDaoimpl;
import com.qf.domain.Cartltem;
import com.qf.domain.Goods;
import com.qf.service.CartService;
import com.qf.service.GoodsService;

import java.math.BigDecimal;
import java.util.List;

public class CartServiceimpl implements CartService {
    private CartDao cartDao=new CartDaoimpl();
    @Override
    public Cartltem selectUserCart(Integer id, Integer goodsld) {
//        获取购物车信息
        Cartltem cartltem=cartDao.selectUserCart(id,goodsld);
        return cartltem;
    }

    @Override
    public void UpdateCartGoods(Integer id, Integer goodsld, BigDecimal price, Integer s) {
        cartDao.UpdateCartGoods(id,goodsld,price,s);
    }

    @Override
    public void InsertUserCart(Integer id, Integer goodsld, Integer number1, BigDecimal price) {
        cartDao.InsertUserCart(id,goodsld,number1,price);
    }

    @Override
    public List<Cartltem> selectUserCartAll(Integer id) {
        List<Cartltem> cartltems=cartDao.selectUserCartAll(id);
        for (Cartltem cartltem:cartltems){
            GoodsService goodsService=new GoodsServiceImpl();
            Goods goods=goodsService.findByid(cartltem.getPid());
            cartltem.setGoods(goods);
        }
        return cartltems;
    }

    @Override
    public void deleteUserCart(Integer id, Integer pid) {
        cartDao.deleteUserCart(id,pid);
    }
}
